home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / output-f.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  3.5 KB  |  158 lines

  1. /* output-file.c -  Deal with the output file
  2.    Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21.  
  22. #include "as.h"
  23.  
  24. #include "output-file.h"
  25.  
  26. #ifdef BFD_HEADERS
  27. #define USE_BFD
  28. #endif
  29.  
  30. #ifdef BFD_ASSEMBLER
  31. #define USE_BFD
  32. #ifndef TARGET_ARCH
  33. #define TARGET_ARCH bfd_arch_unknown
  34. #endif
  35. #ifndef TARGET_MACH
  36. #define TARGET_MACH 0
  37. #endif
  38. #endif
  39.  
  40. #ifdef USE_BFD
  41. #include "bfd.h"
  42. bfd *stdoutput;
  43.  
  44. void 
  45. output_file_create (name)
  46.      char *name;
  47. {
  48.   if (name[0] == '-' && name[1] == '\0')
  49.     {
  50.       as_fatal ("Can't open a bfd on stdout %s ", name);
  51.     }
  52.   else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT)))
  53.     {
  54.       bfd_perror (name);
  55.       as_perror ("FATAL: Can't create %s", name);
  56.       exit (42);
  57.     }
  58.   bfd_set_format (stdoutput, bfd_object);
  59. #ifdef BFD_ASSEMBLER
  60.   bfd_set_arch_mach (stdoutput, TARGET_ARCH, TARGET_MACH);
  61. #endif
  62. }
  63.  
  64. /* output_file_create() */
  65.  
  66.  
  67. void 
  68. output_file_close (filename)
  69.      char *filename;
  70. {
  71. #ifdef BFD_ASSEMBLER
  72.   /* Close the bfd.  */
  73.   if (bfd_close (stdoutput) == 0)
  74.     {
  75.       bfd_perror (filename);
  76.       as_perror ("FATAL: Can't close %s\n", filename);
  77.       exit (42);
  78.     }
  79. #else
  80.   /* Close the bfd without getting bfd to write out anything by itself */
  81.   if (bfd_close_all_done (stdoutput) == 0)
  82.     {
  83.       as_perror ("FATAL: Can't close %s\n", filename);
  84.       exit (42);
  85.     }
  86. #endif
  87.   stdoutput = NULL;        /* Trust nobody! */
  88. }                /* output_file_close() */
  89.  
  90. #ifndef BFD_ASSEMBLER
  91. void 
  92. output_file_append (where, length, filename)
  93.      char *where;
  94.      long length;
  95.      char *filename;
  96. {
  97.   abort ();
  98. }
  99. #endif
  100.  
  101. #else
  102.  
  103. static FILE *stdoutput;
  104.  
  105. void 
  106. output_file_create (name)
  107.      char *name;
  108. {
  109.   if (name[0] == '-' && name[1] == '\0')
  110.     stdoutput = stdout;
  111. #ifdef __MSDOS__
  112.   else if (!(stdoutput = fopen (name, "wb")))
  113. #else
  114.   else if (!(stdoutput = fopen (name, "w")))
  115. #endif
  116.     {
  117.       as_perror ("FATAL: Can't create %s", name);
  118.       exit (42);
  119.     }
  120. }                /* output_file_create() */
  121.  
  122.  
  123.  
  124. void 
  125. output_file_close (filename)
  126.      char *filename;
  127. {
  128.   if (EOF == fclose (stdoutput))
  129.     {
  130.       as_perror ("FATAL: Can't close %s", filename);
  131.       exit (42);
  132.     }
  133.   stdoutput = NULL;        /* Trust nobody! */
  134. }                /* output_file_close() */
  135.  
  136. void 
  137. output_file_append (where, length, filename)
  138.      char *where;
  139.      long length;
  140.      char *filename;
  141. {
  142.  
  143.   for (; length; length--, where++)
  144.     {
  145.       (void) putc (*where, stdoutput);
  146.       if (ferror (stdoutput))
  147.     /* if ( EOF == (putc( *where, stdoutput )) ) */
  148.     {
  149.       as_perror ("Failed to emit an object byte", filename);
  150.       as_fatal ("Can't continue");
  151.     }
  152.     }
  153. }                /* output_file_append() */
  154.  
  155. #endif
  156.  
  157. /* end of output-file.c */
  158.